import {PlusOutlined} from '@ant-design/icons';
import {Button,} from 'antd';
import React, {useState,} from 'react';
import {PageContainer,} from '@ant-design/pro-layout';

import ProTable from '@ant-design/pro-table';

import {hospitalSetIndex} from "@/services/hospital-set/api";

import HospitalSetModalForm from './components/HospitalSetModalForm'
import useHospitalSet from "@/pages/HospitalSet/hooks/useHospitalSet";


const TableList: React.FC = () => {
  const {columns, createModalVisible, handleModalVisible, currentRow, setCurrentRow, actionRef} = useHospitalSet()

  const [, setSelectedRows] = useState<API.RuleListItem[]>([]);


  return (
    <PageContainer>
      <ProTable<API.HospitalSetItem, API.PageParams>
        headerTitle="医院设置"
        size="small"
        options={{density: false}}
        actionRef={actionRef}
        rowKey="id"
        toolBarRender={() => [
          <Button
            type="primary"
            key="primary"
            onClick={() => {
              setCurrentRow(undefined)
              handleModalVisible(true);
            }}
          >
            <PlusOutlined/>
            新建
          </Button>,
        ]}
        request={hospitalSetIndex}
        columns={columns}
        rowSelection={{
          onChange: (_, selectedRows) => {
            setSelectedRows(selectedRows);
          },
        }}
      />
      <HospitalSetModalForm
        createModalVisible={createModalVisible}
        handleModalVisible={handleModalVisible}
        actionRef={actionRef}
        initialValues={currentRow}
      />
    </PageContainer>
  );
};

export default TableList;
